home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fritz: All Fritz
/
All Fritz.zip
/
All Fritz
/
FILES
/
UTILSTEM
/
BAZIC.LZH
/
BAZIC.DOC
< prev
next >
Wrap
Text File
|
1988-11-18
|
34KB
|
872 lines
BAZIC for batch files
version 0.1 (c) copy right 1988 All Rights Reserved
You've seen freewares out there which allow you to get the
time or date as errorlevels to be checked by the batch
commands, right? But how about some BASIC like functions
within your batch files?
What if you can do something like
ON ERRORLEVEL GOTO address1 address2 address3 address4
or better yet, something like
ON ERRORLEVEL GOSUB address1 address2 address3 address4
and
RETURN (mandatory comment here)
?
What if you want to stop someone from using the computer
system while you went to lunch, unless they knew your
password? And it goes without saying that you should be
able to change your password.
What if you can pause and accept keys like this (described
in plain English since you'll have to see the function
itself to see the logic behind it) ?
"If letter 'a', 'A', 'e' or 'E' then set errorlevel to one
to abort and exit the batch command operated menu selection.
If number '1' or letters which look like the number '1',
such as the letters 'I' and 'l', then set errorlevel to two
and run the 123 program.
If the letter 'd' or 'D' or the number '3' or the symbol
'+', then set errorlevel to three to run DBase III plus.
If other keys, ignore them and accept only the above, with
option to either display the key typed or not."
And obviously, you want to get things like month, day of the
month, etc by simply typing something like GET MONTH, right?
If you're the skirmish type who've never used batch commands
and what's built-in to DOS is more than you'll care to want,
then ignore this.
If you're the adventurous type who want batch functions which
start looking more and more like a BASIC program, then try
BAZIC.EXE here.
There is already a sample of what you can do with BAZIC.EXE
in the BAZC.BAT batch file.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
If you simply type
BAZIC
then you get the help list only.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Although this is a program designed to run within a batch
file, a small part of this becomes memory resident.
To initialize the features within BAZIC.EXE (normally
abbreviated to BAZIC), the first line within the batch file
should be
BAZIC RUN
and end it with an <ENTER> or <ntr> or <cr> or anything
else you want to call the carriage return (the document to
follow will always use "<ntr>").
*********************** WARNING *****************************
*Just the letter 'r' in 'run' will NOT! work: Unlike other *
*programs of my group, there is also a BAZIC RETURN, so that*
*your batch file must have at least BAZIC RU to distinguish *
*it from BAZIC RE. *
*************************************************************
As with interpreter BASIC (note the "S"), you can initialize
BAZIC using BAZIC RUN within the batch file, or direct mode
by typing it in yourself from DOS. If you try to run BAZIC
without having initialized it, BAZIC will tell you that the
memory resident part is missing.
Here is the list of functions in this version
BAZIC RUN
BAZIC ON ERRORLEVEL GOTO/GOSUB
BAZIC RETURN mandatory comments
BAZIC INKEY/INKEYOUTKEY
BAZIC GET
BAZIC STOP NEWPASSWORD
BAZIC NEW STACK
The first word after the name of BAZIC.EXE is the function.
So "RUN" is a function, "ON" is a function and "RETURN" is a
function. The other words which follow each function name
are the parameters for that function. So "ERRORLEVEL" is a
parameter, "GOTO" is a parameter and "GOSUB" is a parameter.
You are allowed to abbreviate most of the function names and
the parameters to one or two letters. The exception is with
"INKEYOUTKEY", which can only be shortened to "INKEYO".
The regular and the minimum for abbreviations are mentioned
below. The "ERRORLEVEL" above are shortened to just "ERROR"
below.
This program read a batch file called BAZC.BAT by default in
the directory where you are now in.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
BAZIC RUN
The minimum requirement is
BAZIC RU<ntr>
This must be the first function within your batch file.
This sets up the memory resident part of BAZIC.EXE (referred
to simply as BAZIC) which BAZIC requires in order to operate
properly.
The "<ntr>" stands for the carriage return at the end of a
line. You are not to type the letters. It is used to
visually tell you that there is no letter following them.
There is no need for you to type anything in capital letter,
of course.
It's allright if you try to use this function twice since
BAZIC will detect the presence of a copy of itself already
in memory and will tell you so.
If you did not run this function before some other
functions, you'll get an error on screen telling you that
the memory resident part is not present. And in case you
tried to mix different incompatible versions of BAZIC.EXE,
you'll get a corresponding message telling you of the
conflict as well.
Often, if BAZIC's function detects an error in the batch
file, it places the string
GOTO ERROR<ntr>
in the batch file itself.
As long as there is no label ":ERROR" within your batch
file, this will cause your batch file to stop executing.
Make sure that you leave at least one blank line after each
and every functions. Otherwise, if an error condition
occurs, the next line will be overwritten by the words
"GOTO ERROR".
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
ON ERRORLEVEL GOTO
ON ERRORLEVEL GOSUB
RETURN mandatory comment
The minimum requirement at the moment are
BAZIC O ER GOT ...
BAZIC O ER GOS ...
BAZIC RE . <=each RETURN must have different
and unique comment, even if just
one letter each.
example 1:
BAZIC ON ERROR GOTO DO0 DO1 DO2 DO3 DO4 DO5 DO6 DO7 DO8<ntr>
<ntr>
<ntr>
:DO0<ntr>
...
:DO1<ntr>
...
etc
If ERRORLEVEL = 2, then the batch file wording will be
changed to the following
BAZIC ON ERROR GOTO DO0 DO1 DO2 DO3 DO4 DO5 DO6 DO7 DO8<ntr>
GOTO DO2<ntr>
<ntr>
:DO0<ntr>
...
:DO1<ntr>
...
etc
There is no variable support for this version so that only
the word "ERROR" is acceptable after the "ON" command.
If the word "GOTO" is found (as opposed to the word
"GOSUB"), then the errorlevel is read into BAZIC and
depending on whether the errorlevel is 0 through 8, the
<ntr> on the next line is replaced by the word:
GOTO DO0<ntr>
through
GOTO DO8<ntr>
If the errorlevel is greater than the number of parameters
in the listing, then the <ntr> on the next line is replaced
by the word:
GOTO ERROR<ntr>
Unless your program has a label called ":ERROR", this will
cause your batch program to stop and the batch file will
contain this word (GOTO ERROR<ntr>) to tell you which line
caused it.
Each adddresses, as well as each parameter must be separated
by at least one space or tab.
So, this is not correct.
BAZIC ON ERRORLEVELGOSUBDOTHISANDTHAT
The addresses must not be one letter parameters or a letter
followed by a non-alphabet symbol.
(if people liked this enough to ask for the next version,
BAZIC may mistake it for a variable parameter.)
example 2:
BAZIC ON ERROR GOSUB DO0 DO1 DO2 DO3<ntr>
<ntr>
<ntr>
The ON ... GOSUB must be followed by at least two blank
lines after it. All other functions must have at least one
blank line after it.
As above, a "GOTO DO0" through "GOTO DO3" is generated for
the next line. However, the line is replaced by two lines
composed of an example such as
BAZIC ON ERROR GOSUB DO0 DO1 DO2 DO3<ntr>
GOTO DO1<ntr>
:ZZZ100<ntr>
If you had any comment or commands on the two lines
following the BAZIC ON ERROR GOSUB ..., then those lines are
erased.
The number following the ":ZZZ" part is the line number
of the corresponding BAZIC ON ... here and is stored in the
internal stack. A BAZIC RETURN generates a GOTO based on
the last line number stored in the internal stack. This
also means that if your application program changes the
number of lines of text in your batch file, BAZIC will get
confused and generate incorrect codes.
BAZIC RETURN comment
The minimum requirement at the moment is
BAZIC RE mandatory distinctly different comments
If BAZIC runs with the parameter "RETURN" as in
REM anything you like
BAZIC RETURN individualistic comment needed here<ntr>
<ntr>
then the single <ntr> after this is replaced by "GOTO ZZZ100"
as in
REM anything you like
BAZIC RETURN a distinct comment is needed<ntr>
GOTO ZZZ100<ntr>
If either the GOSUB address is outside the list of
parameters given, or if the internal stack overflowed, then
the line will be replaced by
REM errorlevel is set to 4 or above here
BAZIC ON ERROR GOSUB DO0 DO1 DO2 DO3<ntr>
GOTO ERROR<ntr>
Because BAZIC is not in control all the time, BAZIC does not
really know which BAZIC RETURN in a batch file really called
itself. To help in this, each BAZIC RETURN must be followed
by a comment which is different from any other in the batch
file: The comments may vary by just one letter, an extra
space or anything trivial like a capital letter instead of a
small letter for one word, or long and descriptive.
This is not likely to be a problem with other functions
since if any two are used identically, then they can be made
into a subroutine.
If no GOSUB called this (in other words, you tried to
RETURN without a corresponding GOSUB), then the batch file
is modified to this form to stop the batch command.
REM anything you like
BAZIC RETURN 11anycomment at all<ntr>
GOTO ERROR<ntr>
example 3:
BAZIC RUN<ntr>
goto one<ntr>
:zero<ntr>
BAZIC RETURN a<ntr>
<ntr>
:one<ntr>
BAZIC ON ERROR GOSUB zero one two<ntr>
GOTO zero<ntr>
<ntr>
<ntr>
Once this batch file runs, it generates the following batch
file
BAZIC RUN<ntr>
goto one<ntr>
:zero<ntr>
BAZIC RETURN a<ntr>
GOTO :ZZZ7<ntr>
:one<ntr>
BAZIC ON ERROR GOSUB zero one two<ntr>
GOTO zero<ntr>
:ZZZ7<ntr>
that is assuming that the batch file is allowed to run
without your aborting with control-break.
Of course, when you type one yourself, you do not have to
use capital letters. The BAZIC.EXE name and the functions
are in capital letters to highlight the fact that they are
reserved words and the words you would have choices are in
small letters to denote it.
However, all the codes which BAZIC.EXE itself generates are
always in capital letters, in order to facilitate debugging
your batch file.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
INKEY
BAZIC INKEY
BAZIC INKEY abc d e
BAZIC INKEYOUTKEY abcABC dD eE
The minimum requirement at the moment is
BAZIC I<ntr>
BAZIC INKEYO<ntr>
example 1:
BAZIC INKEY<ntr>
This BAZIC will pause for any ascii typed at the keyboard.
The program will not accept function keys or cursor keys
which do not generate an ascii code, but will accept the
alter key and the numeric key pad combination to generate
chr$(128) through chr$(255).
When the program exits, the errorlevel is set to the
corresponding ascii value of the key typed. For example, if
you had pressed down on the space bar, errorlevel will be
set to 32. <ntr> will set the errorlevel to 13. Therefore,
the errorlevel will always be set to between 1 and 255.
The exception is if you type <esc>; in this case, the
errorlevel is not set to 27 as expected, but is set to zero.
This is a special case since <esc> is generally accepted as
the abort key in most PC programs. This allows your batch
program to check to see if the user wanted to abort at this
point, rather than simply pause here.
But then, what good is typing a letter if you cannot do
anything of much with the letter you typed? In that case,
the next method will allow you finer control.
Unlike regular BASIC's (note that "S" in BASIC) INKEY$
function, where you must do something like
10 a$=inkey$:if a$="" then goto 10
there is no need to loop back in case there is no key.
BAZIC's INKEY will wait until you do type a key.
Also note that within the batch file, if you set echo off,
then the BAZIC INKEY function itself will not display on
screen. However, the BAZIC INKEY function will still be
expecting a key to be typed by you.
example 2:
BAZIC INKEY abcABC Dd eEfG<ntr>
If you typed any of the letters in the first parameter
(abcABC), then the errorlevel is set to one on exit. If
you typed either the "D" or the "d", then the errorlevel is
set to two, and if you type any of the letters in the third
parameter (eEfG), then the errorlevel is set to three.
As with the first example, if you typed <esc>, then the
errorlevel is set to zero. Typing anything else will not
do anything.
Note that this does not allow cursor keys, function keys or
alt key combinations which do not generate any ascii
character either.
Also note that the INKEY is case sensitive. In other words,
the program distinguishes between capital letters and small
letters such that if the example had the parameters
BAZIC INKEY a B C dA<ntr>
then typing "a" sets errorlevel to one, "B" sets errorlevel
to two, "C" sets errorlevel to three and either "d" or "A"
will set errorlevel to four. BAZIC will just wait until
you type one of these five (or <esc>) keys.
You can couple such a command with REMinders such as
REM type "a" to get address book, "d" to find date
REM "A" to Automate everything <esc> to prematurely end
BAZIC INKEY a d A
BAZIC ON ERROR GOTO abort address date automate
example 3:
BAZIC INKEYOUTKEY a b c<ntr>
This behaves just like the regular INKEY, but the key which
you do type is reflected back to the screen and is
displayed to confirm the key you typed.
The key you type is displayed at the cursor location (and
appropriate page location on color graphic adaptor and
enhanced graphic adaptor "CGA and EGA").
This example will display any character you type, but will
not exit until you type the small letters "a", "b" or "c".
Once you type one of the letters, then errorlevel is set to
one, two or three respectively. As with previous examples,
if you type <esc>, then errorlevel is set to zero. (and a
left pointing arrow representing the escape code is
displayed on screen as well.)
Note that as with the previous examples, this is also case
sensitive, so if you want either the capital or the small
letters to respond the same, you must have
BAZIC INKEYOUTKEY aA bB cC<ntr>
And if you want a user forgiving format which allows
accidental use of a number which looks like a letter to be
accepted as a letter, you can try
BAZIC INKEYOUTKEY oO0 iIlL1<ntr>
In this case, the letter "o" or "O" or the number "0" will
set errorlevel to one, while the letter "i" or "I" or "l" or
"L" or the number "1" will set errorlevel to two.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
BAZIC GET date/time
The minimum requirements at the moment is
BAZIC G MO to GET MONTH
BAZIC G D to GET DAY of the month
BAZIC G H to get HOUR
BAZIC G MI to get MINUTE
If it is February 14 at 1:30 PM (in other words 13:30), then
BAZIC GET MONTH
will set errorlevel to 2.
Errorlevel will be between 1 and 13.
BAZIC GET DAY-OF-THE-MONTH
will set errorlevel to 14.
Errorlevel will be between 1 and 31.
BAZIC GET HOUR
will set errorlevel to 13.
Errorlevel will be between 0 and 23.
BAZIC GET MINUTE
will set errorlevel to 30.
Errorlevel will be between 0 and 59.
Note: The ON ERRORLEVEL GOSUB/GOTO is designed so that it
can easily handle over a hundred parameters if need be, so
handling only 60 for each minute of the hour is not a BAZIC
limitation. However, the line command where the addresses
of the ON ... function is on is limited to 128 bytes. Of
course, if I can afford to buy DOS 4.0, maybe the limit is
gone. And again, maybe not.
The above parameters will generate the proper values for DOS
3.3 and below. It is assumed that noone is still using DOS
1.0 or 1.1 with their computer.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
BAZIC STOP
BAZIC STOP NEWPASS
The minimum requirement at the moment is
BAZIC S to stop access on the computer system.
BAZIC S N to assign a new password
In the first mode, BAZIC is waiting for you to type the
internal password before BAZIC will exit, allowing you to
access DOS again. This locks the user from using the
computer: Until you type the correct password, you cannot
get out (except by rebooting).
In the second mode, BAZIC allows any character or string as
"N" at the moment, since there are no other parameter
options for the STOP function anyway. In this mode, BAZIC
will prompt you to enter the old password. If the old
password matches, then BAZIC will prompt you to enter the
new password. This does not lock the user from using the
computer.
In the beginning, the default password is just the carriage
return.
Up to 20 characters can by typed, ending with the gray
carriage return key. If you type control-M or "13" using
the alt key and the numeric key pad, they are stored as part
of the password. Only the gray carriage return key can
terminate the password.
Unlike other passwords, this allows combinations of cursor
keys, function keys, alt key combinations and any other
typeable key combinations as distinctly different key
combinations. Obviously, capital letters and small letters
are distinct and different from each other.
As with interpreter BASIC (note the "S"), this function can
run by itself without being in the batch file, since it
makes sense to use this function from within a batch file or
directly from the DOS prompt B>, C> etc.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
BAZIC NEW STACK
The minimum allowed at the moment is
BAZIC N
This removes all the stack values stored from the
ON ERROR GOSUB ...
At the moment, the only parameter allowed for the NEW
function is to set a new stack so you do not have to type
BAZIC NEW STACK or BAZIC N S.
This does not write the batch file since this will usually
be used from direct mode, as opposed to within a batch file.
While you're debugging your batch file, you may go over the
250 entries limit of the internal stack for the GOSUB.
That's the only reason to use this function. At the moment.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
MESSAGES FROM BAZIC
=-=-=
Unknown and is not in batch command file
=-=-=
This is unknown and you used the direct mode,
instead of trying to use it within the batch file.
BAZIC opened the default batch file BAZC.BAT and searched
inside here to see where the function call came from.
BAZIC couldn't find the line in the batch file in order to
insert the error line (GOTO ERROR).
=-=-=
Each RETURN needs a distinct comment to go with it
=-=-=
You had a BAZIC RETURN without the mandatory comment to go
with it. Because you may run programs, do batch commands or
do anything possible from DOS, BAZIC needs each function to
be distinct from each other. The difference may be just an
extra space or a tab but is essential for BAZIC to tell
itself where it is and where it is going inside the batch
file.
=-=-=
RETURN encountered without a corresponding ON ... GOSUB
=-=-=
There was no BAZIC ON ERRORLEVEL GOSUB ... which has ran
yet, but a BAZIC RETURN (comments) was encountered inside
the batch file. The operation is just like in regular
interpreter BASIC.
=-=-=
The internal stack for ON .. GOSUB overflowed
=-=-=
The ON ... GOSUB can be nested up to 250 levels and should
not normally cause this error, except while debugging your
batch files.
If you want to eliminate the internal stack, try running the
NEW function as in BAZIC NEW STACK.
=-=-=
Memory resident part of BAZIC is not present
=-=-=
BAZIC needs the memory resident part of itself in memory,
initialized using BAZIC RUN.
=-=-=
The memory resident part of BAZIC is the wrong version
to work with this BAZIC. I am aborting.
=-=-=
You mixed the wrong versions of BAZIC. It's best that you
control-break and reboot. This BAZIC has no ability to wipe
itself from memory.
=-=-=
Batch file read and changed but I cannot write the file
=-=-=
The batch file BAZC.BAT was found but was not set to allow
writing the file. Since BAZIC constantly changes the actual
text content of the batch file itself, this will not work.
=-=-=
Unknown parameter found
=-=-=
Something unknown was typed in. Check the batch file and
look for the line with the word "GOTO ERROR". You typed
something BAZIC did not understand on the line previous to
this one.
If your word processor or editor was activated by the very
same BAZC.BAT file, then it can be used to change BAZC.BAT,
or at least used to look at how the batch file is constantly
being changed. It's a good and simple way of debugging your
batch file.
=-=-=
You don't have to do it, BAZIC is already in memory
=-=-=
You did BAZIC RUN twice. No harm done and no extra memory
is used by doing this as many times as you like.
=-=-=
The file length is more than 5000 bytes
If I try to change this, there is going to be trouble.
=-=-=
The batch file is longer than 5000 bytes. This can no
longer be read. This version is designed to work with a
batch file whose maximum size is 5000 bytes.
=-=-=
Enter the old password and end with <ntr>
=-=-=
BAZIC STOP NEWPASS was used to enter a new password to stop
your system. To make sure that you are the person who is
allowed to change the old password, you must type the old
password as it exists in BAZIC right now. You must end this
with the gray carriage return key below the back space key.
The default password is just the carriage return.
If you enter carriage return as control-M or by pressing
down on the alter key and typing out "13" on the numeric key
pad, they are accepted as part of the password.
=-=-=
Now the new password and end with <ntr>
=-=-=
BAZIC STOP NEWPASS accepted the old password as correct.
Now enter the new password, ending with the carriage return.
Up to 20 characters may be used.
You can use a conventional password composed of letters, or
a non-conventional one composed of control-cursor keys,
letters and numbers, shift-function keys, etc etc etc.
=-=-=
This does not match my pass
=-=-=
BAZIC STOP NEWPASS function tried to match your password
with the one stored internally and found that it does not
match.
You are not allowed to change the password unless you can
match the one already in memory.
=-=-=
The file length is zero
=-=-=
The batch file was found but was found to be of length null.
In other words, it's empty.
=-=-=
I cannot find the file.
=-=-=
The batch file was not found.
=-=-=
The file exists but I cannot read it.
=-=-=
The batch file was found but was unable to read it.
CHIT-CHATS
For speed of execution, size of program for what it does,
and the little space it takes on a disk, nothing beats
pure assembler, as are all other programs from my group.
But ohhhhhhhh the pain and time. Merry Xmas and a happy new
year.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
All products and names mentioned are Trademarks or
Registered Trademarks of their respective corporations or
companies.
All enclosed programs, documents and other files are
provided AS IS, without any warranty, expressed or implied,
including but not limited to fitness for a particular
purpose.
A contribution of $10 US/Canadian is appreciated if you
find this useful, or $20 for an improved one. Your
negative criticisms are as welcome as your positive ones.
Suggest any function you would like to see.
NAME OF THE PROGRAM: BAZIC.EXE
PURPOSE OF THIS PROGRAM:
This partly memory resident program is designed to provide
extra BASIC like functions for the batch file commands, such
as ON ERRORLEVEL GOSUB/GOTO address1 address2 address3. As
with the batch file itself, this works best if ran it off a
virtual (RAM) disk.
Most tests have been performed on DOS 3.3 or prior. How it
will behave on DOS 4.0 is not known.
my old forwarding address was
Dr. Masaaki Sawada & Assoc.
University of Waterloo, Faculty of Science
Waterloo, Ontario Canada N2L 3G1
the new forwarding address is
Dr. Masaaki Sawada & Assoc.
Lady Davis Institute for Medical Research,
Sir M. B. Davis Jewish General Hospital,
3755 Chemin Cote Ste-Catherine,
Montreal, Quebec,
Canada H3T 1E2
(you'll find it a lot easier to cut this address out with
your word processor and print it on an envelope, rather
than trying to write it by hand)
The institute name is given instead of home address to
lower the chances that any mail is delivered to a wrong
address (a common occurrence). However no institute time
nor equipment was used to write this program or document.
----------------end-of-author's-documentation---------------
Software Library Information:
This disk copy provided as a service of
The Public (Software) Library
We are not the authors of this program, nor are we associated
with the author in any way other than as a distributor of the
program in accordance with the author's terms of distribution.
Please direct shareware payments and specific questions about
this program to the author of the program, whose name appears
elsewhere in this documentation. If you have trouble getting
in touch with the author, we will do whatever we can to help
you with your questions. All programs have been tested and do
run. To report problems, please use the form that is in the
file PROBLEM.DOC on many of our disks or in other written for-
mat with screen printouts, if possible. The P(s)L cannot de-
bug programs over the telephone.
Disks in the P(s)L are updated monthly, so if you did not get
this disk directly from the P(s)L, you should be aware that
the files in this set may no longer be the current versions.
For a copy of the latest monthly software library newsletter
and a list of the 1,400+ disks in the library, call or write
The Public (Software) Library
P.O.Box 35705 - F
Houston, TX 77235-5705
(713) 665-7017